package com.hig.risk.controller;

import java.util.List;

import com.hig.risk.domain.RiskHazardSource;
import com.ruoyi.common.core.domain.entity.SysDictData;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.hig.risk.domain.RiskInspectionFile;
import com.hig.risk.service.IRiskInspectionFileService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;

/**
 * 自查来源文件Controller
 * 
 * @author scp
 * @date 2024-10-08
 */
@RestController
@RequestMapping("/risk/file")
public class RiskInspectionFileController extends BaseController
{
    @Autowired
    private IRiskInspectionFileService riskInspectionFileService;

    /**
     * 查询自查来源文件列表
     */
    @PreAuthorize("@ss.hasPermi('risk:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(RiskInspectionFile riskInspectionFile)
    {
        startPage();
        List<RiskInspectionFile> list = riskInspectionFileService.selectRiskInspectionFileList(riskInspectionFile);
        return getDataTable(list);
    }

    /**
     * 导出自查来源文件列表
     */
    @PreAuthorize("@ss.hasPermi('risk:file:export')")
    @Log(title = "自查来源文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(RiskInspectionFile riskInspectionFile, HttpServletResponse response)
    {
        List<RiskInspectionFile> list = riskInspectionFileService.selectRiskInspectionFileList(riskInspectionFile);
        ExcelUtil<RiskInspectionFile> util = new ExcelUtil<RiskInspectionFile>(RiskInspectionFile.class);
        util.exportExcel(response,list, "自查来源文件数据");
    }

    /**
     * 获取自查来源文件详细信息
     */
    @PreAuthorize("@ss.hasPermi('risk:file:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(riskInspectionFileService.selectRiskInspectionFileById(id));
    }

    /**
     * 新增自查来源文件
     */
    @PreAuthorize("@ss.hasPermi('risk:file:add')")
    @Log(title = "自查来源文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RiskInspectionFile riskInspectionFile)
    {
        return toAjax(riskInspectionFileService.insertRiskInspectionFile(riskInspectionFile));
    }

    /**
     * 修改自查来源文件
     */
    @PreAuthorize("@ss.hasPermi('risk:file:edit')")
    @Log(title = "自查来源文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RiskInspectionFile riskInspectionFile)
    {
        return toAjax(riskInspectionFileService.updateRiskInspectionFile(riskInspectionFile));
    }

    /**
     * 删除自查来源文件
     */
    @PreAuthorize("@ss.hasPermi('risk:file:remove')")
    @Log(title = "自查来源文件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(riskInspectionFileService.deleteRiskInspectionFileByIds(ids));
    }

    @GetMapping("/optionselect")
    public AjaxResult optionselect()
    {
        RiskInspectionFile riskInspectionFile = new RiskInspectionFile();
        List<SysDictData> list = riskInspectionFileService.selectOptionList(riskInspectionFile);
        return AjaxResult.success(list);
    }
}
